#include<iostream>
#include<vector>
using namespace std;

int duplicate(vector<int>& numbers) {
	if (numbers.size() == 0)
	{
		return -1;
	}
	for (auto e : numbers)
	{
		if (e<0 || e >= (int)numbers.size())
		{
			return -1;
		}

	}
	auto p1 = numbers.begin();
	auto p2 = numbers.end();
	while (p2>p1)
	{
		p2--;
		if (*p1 == *p2&&p1 != p2)
		{
			return *p1;
		
		}
		if (p1 == p2)
		{
			p1++;
			p2 = numbers.end();
		}

	}

	return -1;
}
int main()
{
	vector<int> a = {2,1,3,1,4};
	cout<<duplicate(a)<<endl;
}